package Socket;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Scanner;

public class ClienDome {
    public static void main(String[] args) {
        try {
            Socket socket = new Socket( "192.168.102.81", 9988 );//连接服务器的ip与端口号
            System.out.println( "客户端连接" );
            new Thread( new Runnable() {
                @Override
                public void run() {
                    try {
                        BufferedReader out1 = new BufferedReader( new InputStreamReader( socket.getInputStream() ) );
                        while (true) {
                            String str1 = out1.readLine();
                            System.out.println( str1 );

                        }
                    } catch (IOException e) {
                        e.printStackTrace();

                    }
                }
            } ).start();
            //输出信息
            Scanner scanner = new Scanner( System.in );
            while (true) {
                String str = scanner.nextLine();
                PrintWriter out = new PrintWriter( socket.getOutputStream() );
                out.write( socket.getInetAddress()+"说"+str + "\n" );
                out.flush();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }


    }
}